package com.lagou.homework1_3;

import java.util.Objects;

public class Worker {

    private String name; //姓名
    private int age; //年龄
    private double salary; //工资

    //无参构造
    public Worker() {
    }

    //有参构造
    public Worker(String name, int age, double salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    //重写toString()
    @Override
    public String toString() {
        return "Worker{" + "name='" + name + '\'' + ", age=" + age + ", salary=" + salary + '}';
    }

    //重写equals()
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Worker worker = (Worker) o;
        //(7)为Worker类重写equals 方法，当姓名、年龄、工资全部相等时候才返回true
        return getAge() == worker.getAge() && Double.compare(worker.getSalary(), getSalary()) == 0 && Objects.equals(getName(), worker.getName());
    }

    //重写hashCode()
    @Override
    public int hashCode() {
        return Objects.hash(getName(), getAge(), getSalary());
    }

    //定义work方法
    public void work() {
        System.out.println(name + "正在工作");
    }
}
